package servlet;

import service.RsService;
import service.impl.RsServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet(urlPatterns = "/AddServilet")
public class AddServilet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("utf-8");
        String code = request.getParameter("code");
        String name = request.getParameter("name");
        String sort = request.getParameter("sort");
        String status = request.getParameter("status");
        String time = request.getParameter("time");
        RsServiceImpl service = new RsService();
        int add = service.add(code, name, sort, status,time);
        if (add>0){
            request.setAttribute("massge","<script>alert(\"添加成功!\");</script>");
        }else  {
            request.setAttribute("massge","<script>alert(\"添加失败!\");</script>");

        }
            request.getRequestDispatcher("LoginServlet").forward(request,response);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req, resp);
    }
}
